﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Examples
{
    /// <summary>
    /// Reads CamelotXml file into a DocumentLibraryData object and prints some information about the content
    /// </summary>
    class ReadCamelotXmlToDocumentLibraryData
    {
        public static void DoIt(string xmlFile)
        {
            var xml = System.IO.File.ReadAllText(xmlFile, Encoding.UTF8);

            // first read the xml as ListData
            var listData = Camelot.SharePointIntegration.Client.CamelotXml.ReadXml(xml);

            // second load this as DocumentLibraryData
            var libraryData = Camelot.SharePointIntegration.Client.DocumentLibraryData.CreateDocumentLibraryData(listData);

            if (libraryData.Description != null)
            {
                Console.WriteLine("Description");
                Console.WriteLine("  Id: " + libraryData.Description.ID);
                Console.WriteLine("  Title: " + libraryData.Description.Title);
                Console.WriteLine("  Type: " + libraryData.Description.BaseType);
                Console.WriteLine("  Number of items: " + libraryData.Description.ItemCount);
                Console.WriteLine("  Created: " + libraryData.Description.Created);
                Console.WriteLine("  Last modified: " + libraryData.Description.Modified);
                Console.WriteLine();
            }

            foreach (var doc in libraryData.Documents)
            {
                if (doc.ContentType != "Folder")
                {
                    Console.WriteLine(doc.ProcedureUrl);
                }
            }
        }
    }
}
